package com.xianzhiOA.service.impl;/**
 * Created by Administrator on 2017/5/5.
 */

import com.github.pagehelper.PageHelper;
import com.xianzhiOA.bean.XzTempletBase;
import com.xianzhiOA.dao.XzTempletBaseMapper;
import com.xianzhiOA.service.XzTempletBaseService;
import com.xianzhiOA.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 申请模板基础表Service的实现
 *
 * @author 王诗博
 * @create 2017-05-05 10:05
 **/
@Service("XztempletBaseService")
public class XzTempletBaseServiceImpl implements XzTempletBaseService {
    @Autowired
    private XzTempletBaseMapper templetBaseMapper;

    //添加基础模板表
    @Override
    public int insert(XzTempletBase xzTempletBase) {
        int i=0;
        i=templetBaseMapper.insert(xzTempletBase);
        return i;
    }

    @Override
    public int deleteByPrimaryKey(XzTempletBase xzTempletBase) {
        int i=0;
        i=templetBaseMapper.deleteByPrimaryKey(xzTempletBase);
        return i;
    }

    //根据模板名称查询模板的编号
    @Override
    public Long selByName(String templetName) {
        Long  templetBaseId= null;
        try {
            System.out.println("templetName:"+templetName);
            templetBaseId = templetBaseMapper.selByName(templetName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return templetBaseId;
    }

    @Override
    public XzTempletBase selAllByName(String templetName) {

        XzTempletBase templetBase= null;
        try {
            templetBase = templetBaseMapper.selAllByName(templetName);
            System.out.println("templetBase:"+templetBase);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("e:"+e.toString());
        }

        return templetBase;
    }

    //查询模板基础表中的所有表名
    @Override
    public PageBean<XzTempletBase> selAll(XzTempletBase xzTempletBase, int page, int rows) {
        PageHelper.startPage(page,rows);
        Map<String,Object> map=new HashMap<>();
        map.put("templetName", xzTempletBase.getTempletName());
        List<XzTempletBase> templetBaseList=templetBaseMapper.selAll(map);
        PageBean<XzTempletBase> pb=new PageBean<>(templetBaseList);
        return pb;
    }

    //根据模板ID查询模板表
    @Override
    public XzTempletBase selAllById(Long templetBaseId) {
        XzTempletBase xzTempletBase= null;
        try {
            xzTempletBase = templetBaseMapper.selAllById(templetBaseId);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("e:"+e.toString());
        }
        return xzTempletBase;
    }
    //修改基础模板
    @Override
    public int updateTempletBase(XzTempletBase xzTempletBase) {
        int i=0;

        try {
            i= templetBaseMapper.updateTempletBase(xzTempletBase);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("e:"+e.toString());
        }
        return i;
    }
    //查询基础模板（不分页）
    @Override
    public List<XzTempletBase> selTempletBase() {
        return templetBaseMapper.selTempletBase();
    }
}
